import java.util.ArrayList;
        import java.util.List;
public class homework {
    public static void main(String[] args) {
        UserService userServicer =new UserService();
        System.out.println("-------------------添加--------------");
        userServicer.add(new User("花花",18,"女"));
        userServicer.add(new User("毛毛",19,"男"));
        userServicer.add(new User("小黑",7,"女"));
        userServicer.add(new User("小白",8,"女"));
        System.out.println("-------------------输出结果---------");
        userServicer.print();
        System.out.println("---------------------修改----------");
        userServicer.update(new User("罗小白", 19, "男"));
        System.out.println("---------------------输出-----------");
        userServicer.print();
        System.out.println("---------------------删除----------");
        userServicer.delete("小白");
        System.out.println("---------------------输出-----------");
        userServicer.print();
        System.out.println("---------------------查找-----------");
        User user = userServicer.find("小梦");
        System.out.println(user);
    }
}
class User{
    private String name;
    private int age;
    private String sex;

    public User(String name, int age, String sex) {
        super();
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public String getSex() {
        return sex;
    }
    public void setSex(String sex) {
        this.sex = sex;
    }

    @Override
    public String toString() {
        return "User [name=" + name + ", age=" + age + ", sex=" + sex + "]";
    }

}
class UserService{
    private List<User>user;
    public UserService(){
        user=new ArrayList<User>();
    }
    /**
     * 增加方法
     * @param usr
     */
    public void add(User usr){
        user.add(usr);

    }
    /**
     *
     * @param
     */
    public void update(User user){

        User u=find(user.getName());
        if (u==null){

            return;
        }
        else {
            //修改属性
            u.setAge(user.getAge());
            u.setSex(user.getSex());
        }
    }
    /**
     * 根据名字删除
     * @param name
     */
    public void delete(String name){
        User u=find(name);
        if (u==null){
            return;
        }
        user.remove(u);
    }
    /**
     查找方法，根据名字查
     * @param name
     */
    public User find(String name){

        for(int i=0;i<user.size();i++){
            User u= user.get(i);
            if (u.getName().equals(name)){
                return u;
            }
        }
        return null;
    }
    /**
     * 输出所有用户
     */
    public void print(){
        for(int i=0;i<user.size();i++){
            System.out.println(user.get(i));
        }
    }

}




